# 1. 百度智能云 - 文章标签API
import requests

def baidu_keyword(title,content):
    """文章标签API"""
    url = "https://aip.baidubce.com/rpc/2.0/nlp/v1/keyword?access_token="+access_token
    data = {
        "title" : title,
        "content": content
    }
    encode_data=json.dumps(data).encode('UTF-8')
    headers = {
        'Content-Type':'application/json'
    }
    return requests.post(url,headers=headers,data=encode_data)
    
content_keyword = baidu_keyword("达达主义的诞生","达达主义诞生在欧洲，当时第一次世界大战的恐怖正在相当于公民的前院上演。被迫离开巴黎、慕尼黑和圣彼得堡，一些艺术家、作家和知识分子发现自己聚集在苏黎世（中立的瑞士）提供的避难所里。到1917年年中，日内瓦和苏黎世被前卫运动的头脑淹没，包括汉斯·阿普、雨果·鲍尔、斯特凡·茨威格、特里斯坦·察拉、埃尔斯·拉斯克-舒勒和埃米尔·路德维希。据作家兼记者克莱尔·戈尔说，他们正在从瑞士咖啡馆发生的关于表达主义、立体主义和未来主义的文学和艺术讨论中发明达达会变成什么样子。他们为运动起的名字“Dada”在法语中可能意味着“爱好马”，也可能只是无意义的音节，这是明显荒谬艺术的合适名称。这些作家和艺术家团结在一个松散的团体中，利用他们能找到的任何公共论坛来挑战民族主义、理性主义、唯物主义和他们认为助长了一场毫无意义的战争的任何其他主义。他们说，如果社会朝着这个方向发展，我们将没有它的一部分或传统，尤其是艺术传统。我们是非艺术家，将创造非艺术，因为艺术（和世界上其他一切）无论如何都没有意义。").content
content_keyword_str = str(content_keyword,encoding="GBK")
content_keyword_str_dict =json.loads(content_keyword_str)
content_keyword_str_dict["items"]
# 输出：
# [{'score': 0.937244, 'tag': '达达主义'},
#  {'score': 0.929482, 'tag': '艺术'},
#  {'score': 0.823062, 'tag': '文化'}]


# 2. 百度智能云 - 通用文字识别API
import requests

def baidu_ocr(img_url):
    """通用文字识别"""
    url = "https://aip.baidubce.com/rest/2.0/ocr/v1/general_basic?access_token="+access_token
    params = {
        "url": img_url
    }
    headers = {
        "content-type": "application/x-www-form-urlencoded"
    }
    return requests.post(url, data=params, headers=headers).json()

baidu_ocr("https://dilun.design/wp-content/uploads/2021/01/IMG_A59881A78A57-1.jpeg")
# 输出：
# {'words_result': [{'words': '歌词'},
#   {'words': '见或不见'},
#   {'words': '张敬轩'},
#   {'words': '天空壯闊浩瀚遙望中有過嚮往'},
#   {'words': '不甘各自繁忙人海偏教我們跌宕'},
#   {'words': '更新你我近況人總是要向前望'},
#   {'words': '背影在遠方大世界流浪'}],
#  'log_id': 1347191878272942080,
#  'words_result_num': 7}


# 3. 腾讯云 – 图像标签API
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.tiia.v20190529 import tiia_client, models

cred = credential.Credential("Your SecretId", "Your SecretKey") # 自行填入
httpProfile = HttpProfile()
httpProfile.endpoint = "tiia.tencentcloudapi.com"

clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = tiia_client.TiiaClient(cred, "ap-guangzhou", clientProfile) 

req = models.DetectLabelRequest()
params = {
"ImageUrl": "https://dilun.design/wp-content/uploads/2020/12/pexels-photo-4144923.jpeg"
}
req.from_json_string(json.dumps(params))

resp = client.DetectLabel(req) 
print(resp.to_json_string()) 
# 输出：
# {
#     "Labels":[
#         {
#             "Name":"桌子",
#             "Confidence":84,
#             "FirstCategory":"物品",
#             "SecondCategory":"家具家装"
#         },
#         {
#             "Name":"艺术",
#             "Confidence":79,
#             "FirstCategory":"其他",
#             "SecondCategory":"其他"
#         },
#         {
#             "Name":"人",
#             "Confidence":75,
#             "FirstCategory":"人物",
#             "SecondCategory":"人像"
#         },
#         {
#             "Name":"电脑键盘",
#             "Confidence":74,
#             "FirstCategory":"物品",
#             "SecondCategory":"电子产品及配件"
#         },
#         {
#             "Name":"设计",
#             "Confidence":43,
#             "FirstCategory":"其他",
#             "SecondCategory":"其他"
#         },
#         {
#             "Name":"木头",
#             "Confidence":24,
#             "FirstCategory":"人物",
#             "SecondCategory":"其他"
#         },
#         {
#             "Name":"家具",
#             "Confidence":8,
#             "FirstCategory":"物品",
#             "SecondCategory":"家具家装"
#         },
#         {
#             "Name":"品牌",
#             "Confidence":5,
#             "FirstCategory":"物品",
#             "SecondCategory":"标牌标识"
#         }
#     ],
#     "CameraLabels":null,
#     "AlbumLabels":null,
#     "NewsLabels":null,
#     "RequestId":"bcb1591d-eacc-4418-a62f-6ff0e8be50b8"
# }


# 4. 腾讯云 – 一句话识别API
import json
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.asr.v20190614 import asr_client, models

cred = credential.Credential("Your SecretId", "Your SecretKey") # 自行填入
httpProfile = HttpProfile()
httpProfile.endpoint = "asr.tencentcloudapi.com"

clientProfile = ClientProfile()
clientProfile.httpProfile = httpProfile
client = asr_client.AsrClient(cred, "", clientProfile) 

req = models.SentenceRecognitionRequest()
params = {
    "ProjectId": 0,
    "SubServiceType": 2,
    "EngSerViceType": "16k_ca", # 识别类型选择
    "SourceType": 0,
    "VoiceFormat": "mp3",
    "UsrAudioKey": "hins_test",
    "Url": "https://dilun.design/wp-content/uploads/2021/01/hins_test.mp3"
}
req.from_json_string(json.dumps(params))

resp = client.SentenceRecognition(req) 
print(resp.to_json_string())
# 输出：
# {
#     "Result":"今次喺我拣嗰个方面呢，我都有上网睇到好多嘅留言啦，睇下有冇呢，啲歌系真系大家好想听或者好唔想听嘅啦，系嘛，即系有啲fans话唔想再听到樱花树下，因为事实上，Sorry今晚一定有你放心，唔会令你失望。抢下啦，好话唔好听首本名曲真系冇几多愁。好啦，我啲粉丝成日都嗌开个喎咁转发，真系头都晕埋我啲粉丝成日都幻想我开一个size嘅演唱会，职场嗰啲非主打歌噶。今晚喺呢度不如又试少少俾大家满足。",
#     "AudioDuration":43571,
#     "WordSize":0,
#     "WordList":null,
#     "RequestId":"9f677e36-72fa-417f-99ed-56e1804f3bbe"
# }

# 5. 京东人工智能开放平台 - 视频内容分析API
# 上传视频
url = 'https://aiapi.jd.com/jdai/static_thumbnail'
img = '/Users/apple/Downloads/iPhone12.mp4' # 上传视频的位置
params = { 
    'video' : 'iPhone12.mp4',  # 自行命名
    'appkey' : 'Your appkey',  # 自行填入
    'secretkey' : 'Your secretkey'  # 自行填入
}

response = wx_post_req( url, params, img=img )
print( response.text )
# 输出：
# {"code":"10000","charge":true,"remain":45,"remainTimes":45,"remainSeconds":31533172,"msg":"查询成功,扣费","result":{"code":0,"message":"Success","task_id":"2021-01-07-16-48-10-9f255425ef703c8b439896eacc62849c"}}

# 查询状态
url = 'https://aiapi.jd.com/jdai/static_thumbnail_status'
bodyStr = '{"task_id":"2021-01-07-16-48-10-9f255425ef703c8b439896eacc62849c"}' #body中的内容
params = { 
    'Content-Type' : 'application/json',
    'appkey' : 'Your appkey',  # 自行填入
    'secretkey' : 'Your secretkey'  # 自行填入
}

response = wx_post_req( url, params, bodyStr=bodyStr )
print( response.text )
# 输出：
# {"code":"10000","charge":true,"remain":44,"remainTimes":44,"remainSeconds":31533124,"msg":"查询成功,扣费","result":{"code":0,"editor_result":"http://storage.jd.com/static-thumbnail/2021-01-07-16-48-10-9f255425ef703c8b439896eacc62849c.zip","message":"Finish","progress_rate":100}}
# 下载并解压"editor_result"中的内容，便可得到视频精彩片段截图，进行下一步分析。